<template>
  <el-dialog title="添加计费规则"
             :visible.sync="dialogForm"
             width="1200px"
             append-to-body>
    <base-list ref="addAccountRuleForm"
               :condition="condition"
               :datas.sync="accountGroupData"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               ref="form"
               :model="condition"
               class="search-form"
               slot="search"
               label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="计费规则">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-button plain
                       type="info"
                       icon="el-icon-search"
                       @click="loadData">查 询</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                ref="multipleTable"
                :data="accountGroupData"
                border
                stripe
                @selection-change="handleSelectionChange"
                max-height="500">
        <el-table-column type="selection"
                         width="55">
        </el-table-column>
        <el-table-column label="序号"
                         type="index"
                         width="50">
        </el-table-column>
        <el-table-column prop="feeRuleName"
                         label="计费规则名称"
                         min-width="120"></el-table-column>
        <el-table-column prop="feeUnit"
                         label="计费指标"
                         min-width="120"></el-table-column>
      </el-table>

    </base-list>
    <div style="text-align:center">
      <el-button plain
                 type="info"
                 @click="handleSubmit">确定</el-button>
      <el-button plain
                 type="info"
                 @click="dialogForm = false">返回</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getRuleList } from '@/api/balance/balance' //计费规则
import autoSearchOrg from '@/components/autocomplete/autoSearchOrg'
import autoSearchResource from '@/components/autocomplete/autoSearchResource'
import { PUBLIC_LIMIT } from '@/utils/Reg'

export default {
  name: 'addAccountForm',
  components: {
    autoSearchOrg,
    autoSearchResource
  },
  data() {
    return {
      form: this.clearForm(),
      condition: {}, // 查询条件
      accountGroupData: [], // table数组
      pageSearch: getRuleList, // 分页查询api接口
      id: '',
      dialogForm: false,
      isEdit: false,
      multipleSelection: []
    }
  },
  mounted() {
    // this.loadData()
  },
  methods: {
    loadData() {
      this.$refs.addAccountRuleForm.loadData()
    },
    clearForm() {
      return {
        name: '',
        ramrk: null,
        orgId: '',
        orgId:
          this.$store.state.user.currentUser.org &&
          this.$store.state.user.currentUser.org.id,
        orgName:
          this.$store.state.user.currentUser.org &&
          this.$store.state.user.currentUser.org.name,
        cargoOwnerAccounts: []
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    //确定
    handleSubmit(){
      this.multipleSelection.forEach(element => {
        element.arr = []
      })
      this.$emit('discount',this.multipleSelection)
      this.dialogForm = false

    }
  }
}
</script>

<style scoped>
</style>
